package org.heima.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

public class MyUtil {
    private static SqlSessionFactory MybatisFactory;
    private static SqlSessionFactory MybatisPlusFactory;
    private MyUtil(){

    }

    static {
        try {
            MybatisFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"),"mybatis");
            MybatisPlusFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"),"mybatis-plus");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
    public static SqlSession getMybatisSqlSession(){
        return MybatisFactory.openSession();
    }

    public static SqlSession getMybatisPlusSqlSession(){
        return MybatisPlusFactory.openSession();
    }
}
